package com.wudl.govern.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：wudl
 * @date ：Created in 2022-04-05 21:16
 * @description：
 * @modified By：
 * @version: 1.0
 */
@Slf4j
@Component
public class DispatchrUtils {
    private static final int SUCCESS = 100;




    /**
     * 开启定时任务
     *
     * @param jobId
     * @return
     */
    public static Map onTask(Integer jobId, RestTemplate restTemplate) {
//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.onTask");
//        Map result = RestTemplateUtils.getHttp(restTemplate, url, Map.class, jobId);
//        Map result = executionTaskFeignSV.start(jobId);
        Map result = new HashMap();
        log.info("result: {}", result);
        return result;

    }


    /**
     * 关闭定时任务
     *
     * @param jobId
     * @return
     */
    public static Map offTask(Integer jobId, RestTemplate restTemplate) {
//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.offTask");
//        Map result = RestTemplateUtils.getHttp(restTemplate, url, Map.class, jobId);
//        Map result = executionTaskFeignSV.stop(jobId);
        Map result = new HashMap();
        log.info("result: {}", result);
        return result;

    }

    /**
     * 添加定时任务
     *
     * @param params
     * @return
     */
    public static Map addTask(Map<String, Object> params, RestTemplate restTemplate) {
//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.addTask");
//
//        Map result = RestTemplateUtils.postHttp(restTemplate, url, JSON.toJSONString(params), Map.class);
//        Map result = executionTaskFeignSV.add(params);
        Map result = new HashMap();
        log.info("result: {}", result);

        return result;
    }

    /**
     * 删除定时任务
     *
     * @param jobId
     * @return
     */
    public static Map removeTask(Integer jobId, RestTemplate restTemplate) {

//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.delTask");
//        Map result = RestTemplateUtils.getHttp(restTemplate, url, Map.class, jobId);
        Map result = new HashMap();
        log.info("result: {}", result);
        return result;
    }


    /**
     * 更新任务
     *
     * @param params
     * @return
     */
    public static Map updateTask(Map<String, Object> params, RestTemplate restTemplate) {

//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.updateTask");
//        Map result = RestTemplateUtils.postHttp(restTemplate, url, JSON.toJSONString(params), Map.class);
        Map result = new HashMap();
        log.info("result: {}", result);
        return result;
    }


    /**
     * 单次运行定时任务
     *
     * @param params
     * @return
     */
    public static Map singleTask(Map<String, Object> params, RestTemplate restTemplate) {
//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.singleRun");
//        Map result = RestTemplateUtils.postHttp(restTemplate, url, JSON.toJSONString(params), Map.class);
        Map result =new HashMap();
        log.info("####### result : {}#######", result);
        return result;
    }

    /**
     * 终止任务
     *
     * @param jobId
     * @param restTemplate
     * @return
     */
    public static Map terminationTask(Integer jobId, RestTemplate restTemplate) {
//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.terminationTask");
        Map result = new HashMap();
        log.info("result: {}", result);
        return result;
    }

    /**
     * 查询日志
     *
     * @param params
     * @param restTemplate
     * @return
     */
    public static Map selectExecuteLogger(Map<String, Object> params, RestTemplate restTemplate) {
//        String url = FileHelpper.map.get("service.executionTask") + FileHelpper.map.get("executor.selectExecuteLogger");
//        Map result = RestTemplateUtils.postHttp(restTemplate, url, JSON.toJSONString(params), Map.class);
        Map result = new HashMap();
        log.info("####### result : {}#######", result);
        return result;
    }

}
